package com.lmqb.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lmqb.bean.GrabCarrierBills;
import com.lmqb.bean.GrabCarrierCalls;
import com.lmqb.bean.GrabCarrierFamilies;
import com.lmqb.bean.GrabCarrierNets;
import com.lmqb.bean.GrabCarrierSmses;
import com.lmqb.bean.GrabCarrierUserinfo;
import com.lmqb.bean.GrabFaceRecognition;
import com.lmqb.bean.GrabMobileContacts;
import com.lmqb.bean.GrabQqContacts;
import com.lmqb.bean.GrabQqUserinfo;
import com.lmqb.bean.GrabTaobaoAlipaywealth;
import com.lmqb.bean.GrabTaobaoDeliveraddress;
import com.lmqb.bean.GrabTaobaoRecentdeliveraddress;
import com.lmqb.bean.GrabTaobaoUserinfo;
import com.lmqb.bean.GrabWeixin;
import com.lmqb.bean.GrabXuexin;
import com.lmqb.bean.GrabZhima;
import com.lmqb.bean.JCheckArtificial;
import com.lmqb.bean.JCollection;
import com.lmqb.bean.JRefuseReason;
import com.lmqb.bean.LmAccountLog;
import com.lmqb.bean.LmAgentApply;
import com.lmqb.bean.LmMachineCheckLog;
import com.lmqb.bean.LmRepay;
import com.lmqb.bean.LmUser;
import com.lmqb.bean.LmUserBank;
import com.lmqb.bean.LmUserCheckLog;
import com.lmqb.bean.LmUserEmergency;
import com.lmqb.bean.LmUserInfo;
import com.lmqb.bean.LmUserJob;
import com.lmqb.bean.LmUserLoginLog;
import com.lmqb.bean.LmWithdraw;
import com.lmqb.bean.LogSms;
import com.lmqb.bean.LogWeixin;
import com.lmqb.bean.SysUser;
import com.lmqb.constant.MsgError;
import com.lmqb.constant.MsgSuccess;
import com.lmqb.entry.HeTong;
import com.lmqb.entry.MenuTitle;
import com.lmqb.entry.TuiGuang;
import com.lmqb.entry.UBaseInfo;
import com.lmqb.entry.ULoan;
import com.lmqb.entry.UShow;
import com.lmqb.entry.UUserLoan;
import com.lmqb.page.AgentApplyPager;
import com.lmqb.page.LmDaiLiPager;
import com.lmqb.page.LmUserPager;
import com.lmqb.page.UserBankPager;
import com.lmqb.page.UserChangePager;
import com.lmqb.page.UserEmergencyPager;
import com.lmqb.page.UserJobPager;
import com.lmqb.page.UserLoginPager;
import com.lmqb.page.UserTokenPager;
import com.lmqb.responces.ResultData;
import com.lmqb.service.JiaoYanService;
import com.lmqb.service.LmMachineCheckLogService;
import com.lmqb.service.SysBaseService;
import com.lmqb.service.UserService;
import com.lmqb.util.PageModel;
import com.lmqb.util.StrUtil;

@Controller
public class LmUserController extends BaseController{

	@Autowired
	private JiaoYanService jiaoYanService;
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private SysBaseService sysBaseService;
	
	@Autowired
	private LmMachineCheckLogService lmMachineCheckLogService;
	
	
	//登录令牌信息
	@RequestMapping(value="userToken.html",method=RequestMethod.GET)
	public String toUserToken(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,UserTokenPager pagerModel){
		
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(UserTokenPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			UserTokenPager tokenPager=userService.selectUserTokenPager(pagerModel);
			request.setAttribute(pager, tokenPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userTokenList";
	}
	
	//借款人登录日志
	@RequestMapping(value="userLogin.html",method=RequestMethod.GET)
	public String toUserLogin(HttpSession session,HttpServletRequest request,
		HttpServletResponse response,UserLoginPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			//pagerModel.setUserId(sysUser.getUserId());
			pagerModel=(UserLoginPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			UserLoginPager userLoginPager=userService.selectUserLoginPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, userLoginPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("日志管理");
			menuTitle.setMenu("借款人登录");
			session.setAttribute(menuTitleF, menuTitle);
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userLoginList";
	}
	
    /*
    * 用户列表
    * */
	@RequestMapping(value="lmUser.html",method=RequestMethod.GET)
	public String toLmUser(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LmUserPager pagerModel){
		
		
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LmUserPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			LmUserPager userPager=userService.selectUserPager(pagerModel);
			
			
			
			
			setIfEndty(pagerModel);
			request.setAttribute(pager, userPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("用户管理");
			menuTitle.setMenu("用户列表");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "userList";
	}
	
	//代理商列表
	@RequestMapping(value="lmDaiLi.html",method=RequestMethod.GET)
	public String tolmDaiLi(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LmDaiLiPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LmDaiLiPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			LmDaiLiPager userPager=userService.selectDailiPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, userPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("用户管理");
			menuTitle.setMenu("代理列表");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "dailiList";
	}
   //复借列表
	@RequestMapping(value="lmUserLoanAgin.html",method=RequestMethod.GET)
	public String lmUserLoanAgain(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LmUserPager pagerModel){
		
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LmUserPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			LmUserPager userPager=userService.selectUserPagerAg(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, userPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("用户管理");
			menuTitle.setMenu("复借列表");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "lmUserLoanAgain";
	}
	
	//补充材料用户
	@RequestMapping(value="materialComplenmentary.html",method=RequestMethod.GET)
	public String materialComplenmentary(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LmUserPager pagerModel){
		System.out.println("补充材料");
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LmUserPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			LmUserPager userPager=userService.selectCailiaobucUserPager(pagerModel);
			setIfEndty(pagerModel);
			System.out.println("$$$$$$$$$$$$"+userPager.getList());
			request.setAttribute(pager, userPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("用户管理");
			menuTitle.setMenu("补充材料");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "materialComplenmentary";
	}
	//代理商申请表
	@RequestMapping(value="agentApply.html",method=RequestMethod.GET)
	public String toAgentApply(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,AgentApplyPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(AgentApplyPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			AgentApplyPager agentApplyPager=userService.selectAgentApplyPager(pagerModel);
			request.setAttribute(pager, agentApplyPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "agentApplyList";
	}
	
	//代理商审核
	@RequestMapping(value="agentCheck.html",method=RequestMethod.GET)
	public String agentCheck(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LmDaiLiPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LmDaiLiPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			LmDaiLiPager userPager=userService.selectAgentCheckPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, userPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("用户管理");
			menuTitle.setMenu("代理审核");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "agentCheck";
	}
	
	//代理审核通过
	@RequestMapping(value="agentCheckPass",method=RequestMethod.GET)
	public String agentCheckPass(Integer userId){
		
	
		userService.updateAgentCheckPass(userId);
		return "redirect:agentCheck.html";
	}
	
	    //代理审核不通过
		@RequestMapping(value="agentCheckNoPass",method=RequestMethod.GET)
		public String agentCheckNoPass(Integer userId){
			
			
			userService.updateAgentCheckNoPass(userId);
			return "redirect:agentCheck.html";
		}
	
	//银行卡信息
	@RequestMapping(value="userBank.html",method=RequestMethod.GET)
	public String toUserBank(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,UserBankPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(UserBankPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			UserBankPager userBankPager=userService.selectUserBankPager(pagerModel);
			request.setAttribute(pager, userBankPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userBankList";
	}
	
	//工作信息
	@RequestMapping(value="userJob.html",method=RequestMethod.GET)
	public String toUserJob(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,UserJobPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(UserJobPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			UserJobPager userBankPager=userService.selectUserJobPager(pagerModel);
			request.setAttribute(pager, userBankPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userJobList";
	}
	
	//紧急联系人信息
	@RequestMapping(value="userEmergency.html",method=RequestMethod.GET)
	public String toUserEmergency(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,UserEmergencyPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(UserEmergencyPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			UserEmergencyPager userBankPager=userService.selectUserEmergencyPager(pagerModel);
			request.setAttribute(pager, userBankPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userEmergencyList";
	}
	
	//信息变更表
	@RequestMapping(value="userChange.html",method=RequestMethod.GET)
	public String toUserChange(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,UserChangePager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(UserChangePager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			UserChangePager userBankPager=userService.selectUserChangePager(pagerModel);
			request.setAttribute(pager, userBankPager);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userChangeList";
	}
	
	/*
	 * 用户详情页
	 * 
	 * */
	@RequestMapping(value="userInfo.html",method=RequestMethod.GET)
	public String toUserInfo(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,Integer userId,Model model){
	    PageModel pageM=new PageModel();
		 try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			System.out.println("基本信息");
			//基本信息
			UBaseInfo baseInfo=userService.selectBaseInfo(userId);
			request.setAttribute(baseInfoF, baseInfo);
			//工作信息
			System.out.println("工作信息");
			LmUserJob workInfo=userService.selectWorkInfo(userId);
			request.setAttribute(workInfoF, workInfo);
			//紧急联系人
			LmUserEmergency userEmergency=userService.selectEmergency(userId);
			request.setAttribute(userEmergencyF, userEmergency);
			//银行卡
			LmUserBank userBank=userService.selectUserBank(userId);
			request.setAttribute(userBankF, userBank);
			
			
			//手机情况	从用户登录日志找
			List<LmUserLoginLog> loginLogs=userService.selectLoginLog(request,userId);
			request.setAttribute(loginLogsF, loginLogs);
			//手机通讯列表
			List<GrabMobileContacts> mobiles = userService.selectMobileByUserId(request, userId);
			request.setAttribute("Mobiles", mobiles);

			//短信详情明细
			List<GrabCarrierSmses> carrierSmses=userService.selectSmses(request,userId);
			request.setAttribute(carrierSmsesF, carrierSmses);
			
			
			//网银采集	没有相关的表
			
			//芝麻信用分
			GrabZhima zhima=userService.selectZhiMa(userId);
			request.setAttribute(zhimaF,zhima);
			//运营商抓取信息
			GrabCarrierUserinfo crarrier=userService.selectCrarrier(userId);
			request.setAttribute(carrierF, crarrier);
			
			
			//亲情网
			List<GrabCarrierFamilies> carrierFamilies=userService.selectCarrierFamilies(request,userId);
			request.setAttribute(carrierFamiliesF, carrierFamilies);
			
			
			//账单信息
			List<GrabCarrierBills> carrierBills=userService.selectBills(request,userId);
			request.setAttribute(carrierBillsF, carrierBills);
			System.out.println("账单信息1------>"+carrierBills);
			
			//通话明细
			List<GrabCarrierCalls> carrierCalls=userService.selectCalls(request,userId);
			request.setAttribute(carrierCallsF, carrierCalls);
			
			
			
			
			
			//流量
			List<GrabCarrierNets> carrierNets=userService.selectNets(request,userId);
			request.setAttribute(carrierNetsF, carrierNets);
			
			
			//qq
			List<GrabQqUserinfo> qqUserinfo=userService.selectQQuserINfo(userId);
			request.setAttribute(qqUserinfoF, qqUserinfo);
			
			
			
			//qq好友
			List<GrabQqContacts> qqContacts=userService.selectQQContacts(request,userId);
			request.setAttribute(qqContactsF, qqContacts);
			request.setAttribute("userId", userId);//用户id
			
			
			//淘宝采集字段
			GrabTaobaoUserinfo taobaoBase=userService.selectTaobao(userId);
			request.setAttribute(taobaoBaseF, taobaoBase);
			//支付宝资产
			List<GrabTaobaoAlipaywealth> alipaywealths=userService.selectAlipaywealth(userId);
			request.setAttribute(alipaywealthsF, alipaywealths);
			//淘宝收货地址
			List<GrabTaobaoDeliveraddress> taobaoAddresses=userService.selectTaobaoAddress(userId);
			request.setAttribute(taobaoAddressesF, taobaoAddresses);
			//最近订单的收货地址
			List<GrabTaobaoRecentdeliveraddress> recentAddresses=userService.selectRecentAddress(userId);
			request.setAttribute(recentAddressesF, recentAddresses);
			//学信网采集字段
			GrabXuexin xuexin=userService.selectXueXin(userId);
			request.setAttribute(xuexinF, xuexin);
			//公积金采集字段	没有相关的表
			
			//社保采集字段		没有相关的表
			
			//借款信息
			UUserLoan userLoan=userService.selectUserLoan(userId);
			request.setAttribute(userLoanF, userLoan);
			
			
			//提现列表
			List<ULoan> uloans=userService.selectLoan(request,userId); 
			request.setAttribute(uloansF, uloans);
			
			//微信信息	
			GrabWeixin grabWeiXin=userService.selectWeixin(userId);
			request.setAttribute(grabWeiXinF, grabWeiXin);
			
			//附件信息	
			GrabFaceRecognition face=userService.selectFaceRecognition(userId);
			request.setAttribute(faceF, face);
			
			//账单信息
			//最近的还款记录
			LmRepay repay=userService.selectMaxRepay(userId);
			request.setAttribute(repayF, repay);
			//还款记录
			List<LmRepay> repays=userService.selectReplay(userId);
			System.out.println("还款记录"+repays);
			request.setAttribute(repaysF, repays);
			//借款协议	
			HeTong hetong=new HeTong();
			hetong.setCardNumber(baseInfo.getCardNum());
			if(repay !=null){
				hetong.setRepayTime(repay.getRepayEndTimeD());
			}
			hetong.setUserName(baseInfo.getUserName());
			request.setAttribute(hetongF, hetong);
			
			
			//短信记录	
			List<LogSms> logSmses=userService.selectLogSms(request,userId);
			request.setAttribute(logSmsesF, logSmses);
			
			
			//微信记录	
			List<LogWeixin> logWeixins=userService.selectLogWeixin(request,userId);
			request.setAttribute(logWeixinsF, logWeixins);
			
			
			//推广信息	
			LmUser user=userService.selectByUserId(userId);
			request.setAttribute(userF, user);
			
			
			//推广关系列表
			List<TuiGuang> tuiguangs=userService.selectTuiGuang(userId);
			request.setAttribute(tuiguangsF, tuiguangs);
			
			
			//个人奖励	
			LmAccountLog account=new LmAccountLog();
			account.setUserId(userId);
			account.setTradeType((byte)0);
			List<LmAccountLog> accountLogs=userService.selectAccountLog(request,account);
			request.setAttribute(accountLogsF, accountLogs);
			
			//机审得分
			LmUserCheckLog checkLog=userService.selectMaxCheckLog(userId);
			request.setAttribute(checkLogF, checkLog);
			
			//机审日志
			List<LmMachineCheckLog> lmMachineCheckLogs = lmMachineCheckLogService.selectAllByuserId(userId);
			request.setAttribute("LmMachineCheckLogs", lmMachineCheckLogs);
			
			//获取拒绝原因
			JRefuseReason refuse=new JRefuseReason();
			refuse.setIsDel((byte)0);
			List<JRefuseReason> refuses=userService.selectAllRefuse(refuse);
			request.setAttribute(refusesF, refuses);
			
			//获取当前用户的审核权限  checkType 审核人员权限
			System.out.println(sysUser.getUserId()+">>>>>>>>");
			Integer checkType=userService.selectCheckType(sysUser.getUserId());
			UShow uShow=new UShow();
			uShow.setCheckType(checkType);
			
			Integer checkShow=0;//是否有审核功能，如果没有，则不显示添加审核记录的部分。0：不显示。1：显示
			
			//判断用户状态，如果不是待审核，则不显示添加审核记录部分
			LmUserInfo userInfo=userService.selectUserInfoByUserId(userId);
			
			if(userInfo==null){
				checkShow=0;
			}else{
				uShow.setCheckNo(userInfo.getCheckNo());
				if(userInfo.getAuthStep()==(byte)2||userInfo.getAuthStep()==(byte)5||userInfo.getAuthStep()==(byte)6||userInfo.getAuthStep()==(byte)8||userInfo.getAuthStep()==(byte)9||userInfo.getAuthStep()==(byte)10){
//				if(userInfo.getAuthStep()==(byte)0||userInfo.getAuthStep()==(byte)3){
					if(checkType !=null){
						checkShow=1;
					}
				}else{
					checkShow=0;
				}
			}
			
			uShow.setUserId(userId);
			uShow.setOneCheckId(0);
			//如果是复审、终审，则要获取到初审记录的id
			if(checkType>1){
				JCheckArtificial oneCheck=userService.selectMaxCheck(userId);
				if(oneCheck!=null){
					uShow.setOneCheckId(oneCheck.getCheckOneId());
					if((int)oneCheck.getType()==checkType-1){
						checkShow=1;
					}
				}
				
			}
			uShow.setCheckShow(checkShow);
			
			
			//审核记录
			JCheckArtificial artificial=new JCheckArtificial();
			artificial.setUserId(userId);
			Byte b=null;
			if(checkType!=null&&checkType<(byte)3){
				b=Byte.valueOf(checkType+"");
			}
			artificial.setType(b);
			List<JCheckArtificial> checkArtifs=userService.selectCheckArtifs(artificial);
			request.setAttribute(checkArtifsF, checkArtifs);
			//催收记录
			
			//是否有催收权限
			Integer hasCuiShou=jiaoYanService.selectCuiShou(sysUser.getUserId());
			//最近一条还款记录
			LmRepay yuqi=jiaoYanService.selectYuqi(userId);
			if(yuqi==null){
				hasCuiShou=0;
			}
			uShow.setHasCuiShou(hasCuiShou);
			//逾期订单
			request.setAttribute(yuqiF, yuqi);
			//催收记录
			List<JCollection> cuishous=userService.selectCuiShou(userId);
			request.setAttribute(cuishousF, cuishous);
			//代理申请
			uShow.setCheckAgent(jiaoYanService.CheckApply(sysUser.getUserId()));
			//获取最新的一条申请记录
			LmAgentApply agentApply=userService.selectAgentApply(userId);
			if(agentApply==null||agentApply.getAgentStatus()!=(byte)0){
				uShow.setCheckAgent(0);
			}
			request.setAttribute(agentApplyF, agentApply);
			request.setAttribute(uShowF, uShow);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("用户管理");
			menuTitle.setMenu("用户详情");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "userInfo";
	}
	
	//拒绝理由
	@RequestMapping(value="refuseList.html",method=RequestMethod.GET)
	public String toRefuses(HttpSession session,HttpServletRequest request,
			HttpServletResponse response){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			JRefuseReason reason=new JRefuseReason();
			List<JRefuseReason> list=sysBaseService.selectRefuses(reason);
			request.setAttribute(refusesF, list);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("系统配置");
			menuTitle.setMenu("拒绝理由");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "refuseList";
	}
	
	//人工审核。（初审、复审、终审一起）
	@RequestMapping(value="addCheck",method=RequestMethod.POST)
	@ResponseBody
	public ResultData<String> addCheck(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,Byte checkType,
			Integer oneCheckId,Byte checkStatus,String remark,
			Integer credit,Integer errMsgId,Integer userId,String checkNo){
		System.out.println(oneCheckId);
		ResultData<String> result=new ResultData<String>();
		try{
			JCheckArtificial check=new JCheckArtificial();
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				result.setNotLogin();
				return result;
			}
			check.setAdminId(sysUser.getUserId());
			check.setCredit(new BigDecimal(credit));
			check.setErrMsg(errMsgId);
			check.setRemark(remark);
			check.setStatus(checkStatus);
			check.setType(checkType);
			check.setUserId(userId);
			check.setCheckOneId(oneCheckId);
			check.setCheckLogNo(checkNo);
			LmUserInfo userInfo=userService.selectUserInfoByUserId(userId);
			if(userInfo!=null){ 
				if(checkType==1){
					if(userInfo.getLastUpdateTime()!=null){
						check.setApplyTime(StrUtil.intToTime(userService.selectUserInfoByUserId(userId).getLastUpdateTime()));
					}
				}else{
					
					check.setApplyTime(userService.selectCheckById(oneCheckId).getApplyTime());
				}
			}
			
			result=jiaoYanService.addCheck(check);
			if(result.getStatus()!=0){//状态不为0
				return result;
			}
			check.setCreateTime(new Date());
			System.out.println(check);
			userService.addCheck(check);//添加审核记录
		}catch(Exception e){
			e.printStackTrace();
			result.setError(MsgError.SysErr);
		}
		return result;
	}
	
	//添加催收记录
	@RequestMapping(value="addCuiShou",method=RequestMethod.POST)
	@ResponseBody
	public ResultData<String> addCuiShou(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,Byte status,String repayNo,String remark){
		ResultData<String> result=new ResultData<String>();
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				result.setNotLogin();
				return result;
			}
			JCollection cuishou=new JCollection();
			cuishou.setAdminId(sysUser.getUserId());
			cuishou.setAdminName(sysUser.getLoginName());
			cuishou.setCreateTime(new Date());
			cuishou.setRepayNo(repayNo);
			cuishou.setRemark(remark);
			cuishou.setStatus(status);
			result=jiaoYanService.addCuiShou(cuishou);
			if(result.getStatus()!=0){
				return result;
			}
			userService.addCuiShou(cuishou);
			result.setChengGong(MsgSuccess.ChengGong);
		}catch(Exception e){
			e.printStackTrace();
			result.setError(MsgError.SysErr);
		}
		return result;
	}
	
	//代理审核
	@RequestMapping(value="applyAgent",method=RequestMethod.POST)
	@ResponseBody
	public ResultData<String> applyAgent(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,Byte status,Integer applyId,Integer userId){
		ResultData<String> result=new ResultData<String>();
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				result.setNotLogin();
				return result;
			}
			Integer checkApply=jiaoYanService.CheckApply(userId);
			if(checkApply.intValue()==1){
				LmUser user=new LmUser();
				user.setAgentStatus((byte)(status+1));
				user.setUserId(userId);
				userService.updateUser(user);
				LmAgentApply agentApply=new LmAgentApply();
				agentApply.setApplyId(applyId);
				agentApply.setAgentStatus(status);
				userService.updateAgentApply(agentApply);
			}else{
				result.setError(MsgError.NotCheckPower);
				return result;
			}
		}catch(Exception e){
			e.printStackTrace();
			result.setError(MsgError.SysErr);
		}
		return result;
	}
	
	//qq好友分页 xiugai 7.1
	@RequestMapping(value="qqContactsList",method=RequestMethod.GET)
	@ResponseBody
	public List<GrabQqContacts> qqhaoyou(HttpServletRequest request,Model model,Integer userId){
	   
		List<GrabQqContacts> qqContacts=userService.selectQQContacts(request,userId);
		request.setAttribute(qqContactsF, qqContacts);
		return qqContacts;
		
	}
	//亲情网分页
	@RequestMapping(value="family",method=RequestMethod.GET)
	@ResponseBody
	public List<GrabCarrierFamilies> family(HttpServletRequest request,Integer userId){
	   System.out.println("亲情网");
		List<GrabCarrierFamilies> carrierFamilies=userService.selectCarrierFamilies(request,userId);
	   return carrierFamilies;
		
	}
	
	 //账单分页
     @RequestMapping(value="zhangdan",method=RequestMethod.GET)
	 @ResponseBody
	 public List<GrabCarrierBills>zhangdan (HttpServletRequest request,Integer userId){
		   List<GrabCarrierBills> carrierBills=userService.selectBills(request,userId);
		   System.out.println("运营商账单2---->"+carrierBills);
		   return carrierBills;
			
		}
     //通话明细分页
     @RequestMapping(value="calls",method=RequestMethod.GET)
	 @ResponseBody
	 public List<GrabCarrierCalls>calls (HttpServletRequest request,Integer userId){
		   List<GrabCarrierCalls> carrierCalls=userService.selectCalls(request,userId);
		   return carrierCalls;
			
		}
    
   //短信详情明细
   @RequestMapping(value="smses",method=RequestMethod.GET)
   @ResponseBody
   public List<GrabCarrierSmses>smses (HttpServletRequest request,Integer userId){
		   System.out.println("短信详情");
		   List<GrabCarrierSmses> carrierSmses=userService.selectSmses(request,userId);
		   System.out.println(carrierSmses+"**************");
		   return carrierSmses;
			
		}
   
   //流量
   @RequestMapping(value="nets",method=RequestMethod.GET)
   @ResponseBody
   public List<GrabCarrierNets>nets (HttpServletRequest request,Integer userId){
		   System.out.println("流量详情");
		   List<GrabCarrierNets> carrierNets=userService.selectNets(request,userId);
		   System.out.println(carrierNets);
		   return carrierNets;
			
		}
   
   //短信记录
   @RequestMapping(value="duanxin",method=RequestMethod.GET)
   @ResponseBody
   public List<LogSms>duanxin (HttpServletRequest request,Integer userId){
	   List<LogSms> logSmses=userService.selectLogSms(request,userId);
		
		   return logSmses;
			
		}
   
   //微信记录
   @RequestMapping(value="weixin",method=RequestMethod.GET)
   @ResponseBody
   public List<LogWeixin>weixin (HttpServletRequest request,Integer userId){
	   List<LogWeixin> logWeixins=userService.selectLogWeixin(request,userId);
		return logWeixins;
			
		}
   //位置轨迹
   @RequestMapping(value="weizhi",method=RequestMethod.GET)
   @ResponseBody
   public List<LmUserLoginLog>weizhi (HttpServletRequest request,Integer userId){
	   List<LmUserLoginLog> loginLogs=userService.selectLoginLog(request,userId);
		return loginLogs;
			
		}
   //个人奖励
   @RequestMapping(value="jiangli",method=RequestMethod.GET)
   @ResponseBody
   public List<LmAccountLog>jiangli (HttpServletRequest request,Integer userId){
	    LmAccountLog account=new LmAccountLog();
		account.setUserId(userId);
		account.setTradeType((byte)0);
		List<LmAccountLog> accountLogs=userService.selectAccountLog(request,account);
		return accountLogs;
			
		}
   
   //手机通讯录
   @RequestMapping(value="mobile",method=RequestMethod.GET)
   @ResponseBody
   public List<GrabMobileContacts>mobile(HttpServletRequest request,Integer userId){
	   System.out.println("手机通讯录");
	   List<GrabMobileContacts> mobiles = userService.selectMobileByUserId(request, userId);
		return mobiles;
			
		}
	//初审人员审核的数据
	@RequestMapping(value="checkOne.html",method=RequestMethod.GET)
	public String checkPeopleOne(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,LmUserPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(LmUserPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			pagerModel.setStep(2);
			LmUserPager userPager=userService.selectUserPager(pagerModel);
			setIfEndty(pagerModel);
		    request.setAttribute(pager, userPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("审核管理");
			menuTitle.setMenu("初审");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "checkPeoOne";
	}
	
  //复审人员审核的数据
  @RequestMapping(value="checkTwo.html",method=RequestMethod.GET)
  public String checkPeopleTwo(HttpSession session,HttpServletRequest request,
				HttpServletResponse response,LmUserPager pagerModel){
			try{
				SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
				if(sysUser==null){
					return "login";
				}
				pagerModel=(LmUserPager) jiaoYanService.pagerModelFormat(pagerModel);
				setIfEmpty(pagerModel);
				pagerModel.setStep(5);
				LmUserPager userPager=userService.selectUserPager(pagerModel);
				setIfEndty(pagerModel);
			    request.setAttribute(pager, userPager);
				MenuTitle menuTitle=new MenuTitle();
				menuTitle.setParent("审核管理");
				menuTitle.setMenu("复审");
				session.setAttribute(menuTitleF, menuTitle);
			}catch(Exception e){
				e.printStackTrace();
			}
			
			return "checkPeoTwo";
		}
	
   //终审人员审核的数据
	@RequestMapping(value="checkThree.html",method=RequestMethod.GET)
   public String checkPeopleThree(HttpSession session,HttpServletRequest request,
						HttpServletResponse response,LmUserPager pagerModel){
					try{
						SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
						if(sysUser==null){
							return "login";
						}
						pagerModel=(LmUserPager) jiaoYanService.pagerModelFormat(pagerModel);
						setIfEmpty(pagerModel);
						pagerModel.setStep(6);
						LmUserPager userPager=userService.selectUserPager(pagerModel);
						setIfEndty(pagerModel);
					    request.setAttribute(pager, userPager);
						MenuTitle menuTitle=new MenuTitle();
						menuTitle.setParent("审核管理");
						menuTitle.setMenu("终审");
						session.setAttribute(menuTitleF, menuTitle);
					}catch(Exception e){
						e.printStackTrace();
					}
					
					return "checkPeoThree";
				}
}
